
package com.hmsg.health.dao;

import com.hmsg.health.bean.Dto.TaskDto;
import com.hmsg.health.bean.Dto.WithdrawDto;
import com.hmsg.health.bean.domain.TaskDo;
import com.hmsg.health.bean.domain.UserDo;
import com.hmsg.health.bean.domain.WithdrawDo;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface WithdrawDao {
	
    @Select("select * from t_withdraw where id=#{id}")
    WithdrawDo findOne(@Param("id")Integer id);
    
   
    
    
    @Select("<script>" +
    	    "select * from  `t_withdraw` where 1=1 " +
    	    "    <if test='info.id != null'>" +
    	    "     and `id` = #{info.id} " +
    	    "    </if>" +
    	
    	    "    <if test='info.status != null'>" +
    	    "    and  `status` = #{info.status} " +
    	    "    </if>" +
    	    "    <if test='info.userId != null'>" +
    	    "    and  `user_id` = #{info.userId} " +
    	    "    </if>" +
    	
    	    "    order by id desc" +
    	    "    <if test='info.startNo != null'>" +
    	    "      limit #{info.startNo},#{info.pageSize}" +
    	    "    </if>" +
    	    "</script>")
    List<WithdrawDo> select(@Param("info") WithdrawDo info);
    
    
   
    @Delete("delete from t_withdraw where id=#{userId}")
    int delete(Integer userId);
    
  
    @Insert("<script>" +
    "insert into `t_withdraw` " +
    "  <set>" +
    "    <if test='info.status != null'>" +
    "     `status` = #{info.status}, " +
    "    </if>" +
    "    <if test='info.userId != null'>" +
    "      `user_id` = #{info.userId}, " +
    "    </if>" +
    "    <if test='info.amount != null'>" +
    "      `amount` = #{info.amount}, " +
    "    </if>" +
    "    <if test='info.accountNum != null'>" +
    "      `account_num` = #{info.accountNum}, " +
    "    </if>" +
    "    <if test='info.accountName != null'>" +
    "      `account_name` = #{info.accountName}, " +
    "    </if>" +
    "    <if test='info.gload != null'>" +
    "      `gload` = #{info.gload}, " +
    "    </if>" +
  
    "    <if test='info.createTime != null'>" +
    "      `create_time` = #{info.createTime} " +
    "    </if>" +
    "  </set>" +
    "</script>")
	@Options(useGeneratedKeys = true, keyProperty = "id")
	int save(@Param("info") WithdrawDo info);



	@Select("<script>" +
			" select a.* from t_withdraw  a   left join s_user u on a.user_id= u.id" +
			"   where 1=1  " +
			"    <if test='state != null '>" +
			"     and a.status=#{state} " +
			"    </if>" +
			"    <if test='phone != null '>" +
			"     and u.mobile=#{phone} " +
			"    </if>" +
			"    <if test='time != null '>" +
			"   and  DATE_FORMAT(a.create_time, '%Y-%m-%d') = DATE_FORMAT(#{time},'%Y-%m-%d') " +
			"    </if>" +
			"    order by a.id desc" +
			" limit #{firstResult},#{maxResult}"+
			"</script>")
    List<WithdrawDto> findAll(@Param("state") Integer state,@Param("phone") String phone,
							  @Param("time") String time,
							  @Param("firstResult") Integer firstResult,
							  @Param("maxResult") Integer maxResult);



	@Select("<script>" +
			" select count(a.id) from t_withdraw  a   left join s_user u on a.user_id= u.id" +
			"   where 1=1  " +
			"    <if test='state != null '>" +
			"     and a.status=#{state} " +
			"    </if>" +
			"    <if test='phone != null '>" +
			"     and u.mobile=#{phone} " +
			"    </if>" +
			"    <if test='time != null '>" +
			"   and  DATE_FORMAT(a.create_time, '%Y-%m-%d') = DATE_FORMAT(#{time},'%Y-%m-%d') " +
			"    </if>" +
			"</script>")
	int countAll(@Param("state") Integer state,@Param("phone") String phone,
							  @Param("time") String time);














	@Update({"<script>",
			"UPDATE  t_withdraw",
			"<trim prefix='set' suffixOverrides=','>",

			"<if test='withdrawDo.status!=null'>",
			"status= #{withdrawDo.status},",
			"</if>",
			"</trim>",
			"where id = #{withdrawDo.id}",
			"</script>"})
	void update(@Param("withdrawDo") WithdrawDo withdrawDo);
}